/*     */ package cn.com.hongpay.client.anal;
/*     */ 
/*     */ import cn.com.hongpay.client.utils.SignatureTools;
/*     */ import cn.com.hongpay.client.vo.pay.SinglePayResVo;
/*     */ import cn.com.hongpay.client.vo.query.QueryResVo;
/*     */ import cn.com.hongpay.client.vo.refund.RefundResVo;
/*     */ import java.io.PrintStream;
/*     */ 
/*     */ public class ResMsgAnalyze extends XmlAnalyze
/*     */ {
/*     */   private String cerFile;
/*     */   private String charset;
/*     */ 
/*     */   public String getCharset()
/*     */   {
/*  14 */     return this.charset;
/*     */   }
/*     */ 
/*     */   public void setCharset(String charset) {
/*  18 */     this.charset = charset;
/*     */   }
/*     */ 
/*     */   public ResMsgAnalyze(String cerFile) {
/*  22 */     this.cerFile = cerFile;
/*     */   }
/*     */ 
/*     */   public SinglePayResVo verifyPayNotifyMsg(String payNotifyXml)
/*     */     throws Exception
/*     */   {
/*  33 */     if (verifySign(payNotifyXml))
/*     */     {
/*  35 */       return getPayNotifyVo(payNotifyXml);
/*     */     }
/*     */ 
/*  38 */     return null;
/*     */   }
/*     */ 
/*     */   public QueryResVo verifyQueryResMsg(String queryResXml)
/*     */     throws Exception
/*     */   {
/*  49 */     if (verifySign(queryResXml))
/*     */     {
/*  51 */       return getQueryResVo(queryResXml);
/*     */     }
/*     */ 
/*  54 */     return null;
/*     */   }
/*     */ 
/*     */   public RefundResVo verifyRefundResMsg(String refundResXml)
/*     */     throws Exception
/*     */   {
/*  65 */     if (verifySign(refundResXml))
/*     */     {
/*  67 */       return getRefundResVo(refundResXml);
/*     */     }
/*     */ 
/*  70 */     return null;
/*     */   }
/*     */ 
/*     */   public RefundResVo verifyRefundNotifyResMsg(String refundResXml)
/*     */     throws Exception
/*     */   {
/*  81 */     if (verifySign(refundResXml))
/*     */     {
/*  83 */       return getRefundResVo(refundResXml);
/*     */     }
/*     */ 
/*  86 */     return null;
/*     */   }
/*     */ 
/*     */   private boolean verifySign(String resMsg)
/*     */   {
/*     */     try {
/*  92 */       int signBegin = resMsg.indexOf("<SIGNED_MSG>");
/*  93 */       int signEnd = resMsg.indexOf("</SIGNED_MSG>");
/*     */ 
/*  95 */       String sign = resMsg.substring(signBegin + "<SIGNED_MSG>".length(), signEnd);
/*  96 */       String plainText = resMsg.substring(0, signBegin + "<SIGNED_MSG>".length()) + resMsg.substring(signEnd);
/*  97 */       if ((this.charset != null) && (this.charset.trim().length() > 0)) {
/*  98 */         return SignatureTools.verifySignatureWithCharset(sign, plainText, this.cerFile, this.charset);
/*     */       }
/* 100 */       return SignatureTools.verifySignature(sign, plainText, this.cerFile);
/*     */     }
/*     */     catch (Exception e) {
/* 103 */       System.out.println("验证签名失败：" + e.getMessage());
/* 104 */     }return false;
/*     */   }
/*     */ }

/* Location:           F:\hongpay_client.jar
 * Qualified Name:     cn.com.hongpay.client.anal.ResMsgAnalyze
 * JD-Core Version:    0.6.0
 */